<#assign dtoClass = entity + "DTO">
<#assign voClass = entity + "VO">
<#assign dtoParam = entity?substring(0,1)?lower_case + entity?substring(1) + "DTO">
<#assign entityParam = entity?substring(0,1)?lower_case + entity?substring(1)>
<#assign repositoryParam = entity?substring(0,1)?lower_case + entity?substring(1) + "Repository">
<#assign convertParam = entity?substring(0,1)?lower_case + entity?substring(1) + "Convert">
<#assign tableComment = table.comment!?substring(0, table.comment!?length - 1)>
package ${package.ServiceImpl};

import ${convertPackage}.${entity}Convert;
import ${repositoryPackage}.${entity}Repository;
import ${dtoPackage}.${dtoClass};
import ${voPackage}.${voClass};
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};

import cn.com.blueInfo.core.util.SnowflakeIdGenerator;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* ${table.comment!} 业务服务实现类
* @author ${author}
* @since ${date}
*/
@Log4j2
@Service
public class ${table.serviceImplName} implements ${table.serviceName} {

    @Autowired
    private ${entity}Repository ${repositoryParam};

    @Autowired
    private SnowflakeIdGenerator snowflakeIdGenerator;

    @Autowired
    private ${entity}Convert ${convertParam};

    /**
    * 新增${tableComment}
    * @param ${dtoParam} ${tableComment}参数
    */
    @Override
    public ResultInfo add${entity}(${dtoClass} ${dtoParam}) {
        ${entity} ${entityParam} = ${convertParam}.dtoToEntity(${dtoParam});
        ${entityParam}.setId(snowflakeIdGenerator.nextId());
        Integer addSize = ${repositoryParam}.create${entity}(${entityParam});
        return ResultInfo.builder().data(addSize).message("${tableComment}成功新增 {} 条").build();
    }

    /**
    * 删除${tableComment}
    * @param ${entityParam}Id ${tableComment}ID
    */
    @Override
    public ResultInfo remove${entity}(String ${entityParam}Id) {
        Integer removeSize = ${repositoryParam}.delete${entity}(${entityParam}Id);
        return ResultInfo.builder().data(removeSize).message("${tableComment}成功删除 {} 条").build();
    }

    /**
    * 更新部分${tableComment}
    * @param ${dtoParam} ${tableComment}参数
    */
    @Override
    public ResultInfo modify${entity}Partial(${dtoClass} ${dtoParam}) {
        ${entity} ${entityParam} = ${convertParam}.dtoToEntity(${dtoParam});
        Integer modifySize = ${repositoryParam}.update${entity}Partial(${entityParam});
        return ResultInfo.builder().data(modifySize).message("${tableComment}成功更新 {} 条").build();
    }

    /**
    * 更新全部${tableComment}
    * @param ${dtoParam} ${tableComment}参数
    */
    @Override
    public ResultInfo modify${entity}(${dtoClass} ${dtoParam}) {
        ${entity} ${entityParam} = ${convertParam}.dtoToEntity(${dtoParam});
        Integer modifySize = ${repositoryParam}.update${entity}(${entityParam});
        return ResultInfo.builder().data(modifySize).message("${tableComment}成功更新 {} 条").build();
    }

    /**
    * 查询一条${tableComment}
    * @param ${entityParam}Id ${tableComment}ID
    */
    @Override
    public ResultInfo query${entity}ById(String ${entityParam}Id) {
        ${entity} ${entityParam} = ${repositoryParam}.get${entity}ById(${entityParam}Id);
        ${voClass} ${entityParam}VO = ${convertParam}.entityToVO(${entityParam});
        return ResultInfo.builder().data(${entityParam}VO).message("${tableComment}查询成功").build();
    }

    /**
    * 分页查询${tableComment}
    * @param ${dtoParam} ${tableComment}参数
    */
    @Override
    public ResultInfo query${entity}Page(${dtoClass} ${dtoParam}) {
        ${entity} ${entityParam} = ${convertParam}.dtoToEntity(${dtoParam});
        Page<${entity}> ${entityParam}Page = ${repositoryParam}.get${entity}Page(
                ${entityParam}, ${dtoParam}.getPage(), ${dtoParam}.getSize());
        Page<${voClass}> resultData = ${convertParam}.convertPage(${entityParam}Page);
        return ResultInfo.builder()
                .data(resultData)
                .message("${tableComment}分页查询成功，共 {} 条", resultData.getRecords().size())
                .build();
    }
}
    